/*
 * 统计模块业务统计出院js
 * @author 杨腊梅
 * 2016/1/20
 * 
 */


$('#tcm_businessTemMedicine_eCharts').css('height',orange.detailPage.getHeight());
$('#tcm_businessTemMedicine_eCharts').css('width',orange.detailPage.getWidth());
$('#btm_monthDate').val(new Date().Format('yyyy'));
$('#tcm_businessTemMedicine_grid').datagrid({
	url:'d/medicine/table',
	queryParams:{
		orgGuid:$("#tcmcpdetail_guid").val(),
		year:$("#btm_monthDate").val()
	},
	singleSelect:true,
	rownumbers:true,
	columns:[[
	          {field:'month',title:'月份',width:'12%',sortable:true,align:'center'},
	          {field:'outTcmd',title:'门诊中药饮片方总数',width:'12%',sortable:true,halign:'center'},
	          {field:'outTcmsp',title:'门诊中成药方总数',width:'12%',sortable:true,halign:'center'},
	          {field:'outTcmdu',title:'门诊药食两用总数',width:'12%',sortable:true,halign:'center'},
	          {field:'outTcmpe',title:'门诊中药方总金额',width:'12%',sortable:true,halign:'center'},
	          {field:'outTcmpePCT',title:'占比',width:'7%',sortable:true,halign:'center'},
	          {field:'inTcmp',title:'住院中药方总数',width:'12%',sortable:true,halign:'center'},
	          {field:'inTcmpe',title:'住院中药方总金额',width:'12%',sortable:true,halign:'center'},
	          {field:'inTcmpePCT',title:'占比',width:'7%',sortable:true,halign:'center'}
	          ]],
	pagination:true,
	sortable:true,
	sortName:'tcm_time',
	sortOrder:'asc'
});
/**
 * 查询中医药
 */
function businessTemMedicine_query(){
	$('#tcm_businessTemMedicine_grid').datagrid({
		url:'d/medicine/table',
		queryParams:{
			orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#btm_monthDate").val()
		}
	})
	initbusinessTemMedicineChartData();
}
/*
 * 图表数据初始化
 */
var tcm_myChart = echarts.init($('#tcm_businessTemMedicine_eCharts')[0]);
var tcm_initData;
var tcm_serial_Medicine_usage = [];
var tcm_serial_Medicine_amountOfMoney = [];
var tcm_xData = [];
initbusinessTemMedicineChartData();
function initbusinessTemMedicineChartData(){
	tcm_serial_Medicine_usage.length = 0;
	tcm_serial_Medicine_amountOfMoney.length = 0;
	tcm_xData.length = 0;
	$.ajax({
		url:"d/medicine/chart",
		type:"get",
		data:{orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#btm_monthDate").val()},
		success:function(data){
			tcm_initData = JSON.parse(data);
			tcm_initData = tcm_initData.chart2;
			for(var i=0; i<tcm_initData.length; i++) {
				tcm_serial_Medicine_usage.push(tcm_initData[i].outTcmpe);
				tcm_serial_Medicine_amountOfMoney.push(tcm_initData[i].inTcmpe);
				tcm_xData.push(tcm_initData[i].period);
			}
			tcm_myChart = echarts.init($('#tcm_businessTemMedicine_eCharts')[0]);
			tcm_myChart.setOption(tcm_option);
		}
	});
}

/*
 * 设置图表格式
 */
tcm_option={
		grid:{
			show:false,
			bottom :'15%',
			top:'25%',
			height:'65%',
			width:'80%',
			left:'10%',
			right:'15%'
		},
		tooltip : {
			trigger : 'axis'
		},
		
		legend : {
			top : '5%',
			data : ['中医药用量', '中医药总金额/万']
		},
		
		xAxis : [{
			type : 'category',
			boundaryGap : false,
			data : tcm_xData
		}],
		
		yAxis : [{
			type:'value'
		}],
		
		series : [
		  {
			  type : 'line',
			  name : "中医药用量",
			  smooth : true,
			  data : tcm_serial_Medicine_usage
		  },
		  {
			  type : 'line',
			  name : "中医药总金额/万",
			  smooth : true,
			  data : tcm_serial_Medicine_amountOfMoney
		  }
		],
};

//使用刚指定的配置项和数据显示图表
tcm_myChart.setOption(tcm_option);